package com.topscomm.file.service;

import java.util.Map;

import com.topscomm.file.FileProperties;
import com.topscomm.file.convert.factory.FileConvertDispatcher;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.SpringUtil;

/**
 * 文件转换处理器
 * 
 * @description:
 * @author: donghang
 * @date: 2021年3月14日下午10:47:07
 * @modify:
 */
public class FileConvertFilter implements IFileProcessFilter {
	/**
	 * 
	 * @description:
	 * @author: donghang
	 * @date: 2020年8月21日上午11:34:03
	 * @modify:
	 */
	public FileConvertFilter() {

	}

	/**
	 * 文件格式转换处理
	 * 
	 * @description:
	 * @param paraMap
	 * @param dataProcessChain
	 * @return
	 * @author: donghang
	 * @date: 2021年3月16日上午9:03:05
	 * @modify:
	 */
	@Override
	public boolean doProcess(Map<String, Object> paraMap, IFileProcessChain dataProcessChain) throws Exception {
		FileConvertDispatcher fileConvertDispatcher = (FileConvertDispatcher) SpringUtil
				.getBean("fileConvertDispatcher");
		FileProperties fileProperties = (FileProperties) SpringUtil.getBean("fileProperties");
		String fileName = ConvertUtil.convertToString(paraMap.get("filename"));
		String identifier = ConvertUtil.convertToString(paraMap.get("identifier"));
		StringBuilder filePath = new StringBuilder();
		// 本地的文件
		filePath.append(fileProperties.getStorePath()).append("/").append(identifier).append("/").append(fileName);
		StringBuilder targetFilePath = new StringBuilder();
		targetFilePath.append(fileProperties.getStorePath()).append("/").append(identifier).toString();
		// 线程池调度转换文件
		fileConvertDispatcher.handle(filePath.toString(), targetFilePath.toString(), identifier);
		if (dataProcessChain != null) {
			dataProcessChain.doProcess(paraMap);
		}
		return true;
	}

}
